package com.gdzn.signal.service.impl;

import cn.hutool.json.JSONUtil;
import com.gdzn.signal.mongo.document.*;
import com.gdzn.signal.mongo.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SignalServiceImpl {

    @Autowired
    private IMgSignalAlarmService mgSignalAlarmService;

    @Autowired
    private MgSignalAttributeService mgSignalAttributeService;

    @Autowired
    private MgSignalCmdControlService mgSignalCmdControlService;

    @Autowired
    private MgSignalCmdQconfigService mgSignalCmdQconfigService;

    @Autowired
    private MgSignalLoginService mgSignalLoginService;


    public void saveSignal(MgSignal signal) {
        log.info("signal:{}",signal);
        log.info("signal:"+ JSONUtil.toJsonStr(signal));
    }

    public void saveSignal(MgSignalAlarm signal) {
        mgSignalAlarmService.insert(signal);
    }

    public void saveSignal(MgSignalAttribute signal) {
        mgSignalAttributeService.insert(signal);
    }

    public void saveSignal(MgSignalCmdControl signal) {
        mgSignalCmdControlService.insert(signal);
    }

    public void saveSignal(MgSignalCmdQconfig signal) {
        mgSignalCmdQconfigService.insert(signal);
    }

    public void saveSignal(MgSignalLogin signal) {
        mgSignalLoginService.insert(signal);
    }

    public MgSignalAttribute getAttribute(String devId) {
        MgSignalAttribute attribute = new MgSignalAttribute ();
        attribute.setDevId(devId);
//        attribute.setIsFull("1");
        MgSignalAttribute result = mgSignalAttributeService.getLatestAttribute(attribute);
        return result;
    }
}
